#!/usr/bin/env make
###############################################################################
#
#  Copyright (c) Hunan Goke,Chengdu Goke,Shandong Goke. 2021.
#  All rights reserved.
#  Create By Caizhiyong 2021/3/16
#
###############################################################################

BUSYBOX := busybox-1_26_2

BUSYBOX_PREFIX = $(ROOTFS_BUILDDIR)/$(BUSYBOX)/.install

MKFLAGS_BUSYBOX = $(MKFLAGS) V=1
MKFLAGS_BUSYBOX += CROSS_COMPILE=$(CONFIG_GK_ARM_TOOLCHAINS_NAME)-
MKFLAGS_BUSYBOX += CONFIG_PREFIX=$(BUSYBOX_PREFIX)
MKFLAGS_BUSYBOX += CFLAGS="$(SDK_USR_CFLAGS)"

rootfs_unstrip: $(ROOTFS_PREFIX)/bin/busybox

clean: $(BUSYBOX).clean

$(BUSYBOX).clean:
	$(AT)rm -rf $(ROOTFS_BUILDDIR)/$(BUSYBOX)

$(ROOTFS_PREFIX)/bin/busybox: $(ROOTFS_BUILDDIR)/$(BUSYBOX)/.built
	$(call mkdir,$(@D))
	cp -arf $(BUSYBOX_PREFIX)/. $(ROOTFS_PREFIX)
	touch $@

$(ROOTFS_BUILDDIR)/$(BUSYBOX)/.built: $(ROOTFS_BUILDDIR)/$(BUSYBOX)/.extracted
	make -C $(<D) $(MKFLAGS_BUSYBOX) all
	make -C $(<D) $(MKFLAGS_BUSYBOX) install
	touch $@

$(ROOTFS_BUILDDIR)/$(BUSYBOX)/.extracted:
	$(call mkdir,$(@D))
	tar -xf $(OPEN_SOURCE_DIR)/busybox/$(BUSYBOX).tar.gz -C $(ROOTFS_BUILDDIR)
	cp -arf $(ROOTFS_SRCDIR)/busybox/$(BUSYBOX).patch/. $(@D)
	cp -f $(ROOTFS_SRCDIR)/busybox/$(CONFIG_GK_BUSYBOX_CFG_NAME).config $(@D)/.config
	touch $@
